<?php
/* 记录最开始的时间。*/
$timeStart = _getTime();

/* 包含必须的类文件。*/
include '../../../framework/error.class.php';
include '../../../framework/router.class.php';
include '../../../framework/control.class.php';
include '../../../framework/model.class.php';
include '../../../framework/helper.class.php';

try {
	/* 实例化路由对象，并加载配置，连接到数据库，加载common模块。*/
	$app    = router::createApp('demo', dirname(dirname(__FILE__)));
	$config = $app->loadConfig('common');
	$common = $app->loadCommon();
	
	
	/* 设置客户端所使用的语言、风格。*/
	$app->setClientLang();
	$app->setClientTheme();

	/* 处理请求，加载相应的模块。*/
	$app->parseRequest();
	$app->loadModule();
} catch (Exception $e) {
	// 输出JSON格式错误
	$ecode = $e->getCode();
	$result = array(
		'code' => $ecode,
		'message' => sprintf( "Exception:  %s \n %s", $e->getMessage(), $e->getTraceAsString() )
	);
	if($ecode!=403)
		//helper::datalog('inside|'.$ecode.'|'.$e->getMessage(),'syslog_');
    header("Content-Type:	application/json");
	echo json_encode($result);
}

/* 获取系统时间，微秒为单位。*/
function _getTime()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
